<?php
$user_id = $_SESSION['group'];

$cmpyName = $_SESSION['cname'];
$query = "select * from tbl_companies where c_nickname = '$cmpyName'";
$result = mysql_query($query);
$c_res = mysql_fetch_array($result);

$cid = $c_res['ct_id'];
$ct_query = "select tbl_companies.ct_id,tbl_company_type.ct_company from tbl_companies inner join tbl_company_type on tbl_companies.ct_id = tbl_company_type.ct_id where tbl_companies.ct_id = $cid";
$ct_result = mysql_fetch_array(mysql_query($ct_query));

$rptid = $c_res['reporting_type'];
$report_query = "select tbl_companies.reporting_type,tbl_reporting_type.reporting_type from tbl_companies inner join tbl_reporting_type on tbl_companies.reporting_type = tbl_reporting_type.rpt_id where tbl_companies.reporting_type = $rptid";
$report_result = mysql_fetch_array(mysql_query($report_query));

extract($_POST);
$update_query = "UPDATE tbl_companies SET c_billing_address1='$c_billing_address1',c_billing_address2='$c_billing_address2'," .
						"c_billing_city='$c_billing_city',c_billing_state='$c_billing_state',c_billing_zipcode='$c_billing_zipcode',c_billing_country='$c_billing_country',c_phone_number='$c_phone_number'," .
						"c_phone_extension='$c_phone_extension',c_fax_number='$c_fax_number' WHERE c_id=$chidden";
$update_info = mysql_query($update_query);
if($update_info){?>
				<script>
				$(document).ready(function(){
					 $("#success").text("Company Information Updated Successfully!").show();
					 return false;
				});
				</script>
				<?}

$query = "select * from tbl_companies where c_nickname = '$cmpyName'";
$result = mysql_query($query);
$c_res = mysql_fetch_array($result);
?>
<span id='error'></span><span id='success'></span>
<fieldset style="font-size: 11px;">
<legend><h4>Company Information</h4></legend>
<form action="" method="post" id="editCompInfofrm">
<table cellpadding="4">
	<tr>
		<td><strong>Company Name* :</strong></td>
		<td><span style="color:#0762A3"><?=$c_res['c_name'];?></span></td>
	</tr>
	<tr>
		<td><strong>Company Nickname* :</strong></td>
		<td><span style="color:#0762A3"><?=$c_res['c_nickname'];?></span></td>
	</tr>
	<tr>
		<td><strong>Company Type :</strong></td>
		<td><span style="color:#0762A3"><?=$ct_result['ct_company'];?></span></td>
	</tr>
	<tr>
		<td><strong>Reporting Type :</strong></td>
		<td><span style="color:#0762A3"><?=$report_result['reporting_type'];?></span></td>
	</tr>
	<? if($user_id == 2){?>
	<tr>
		<td><strong>Billing Address1 :</strong></td>
		<td><input type="text" name="c_billing_address1" value="<?=$c_res['c_billing_address1'];?>" id="c_billing_address1"/></td>
	</tr>
	<tr>
		<td><strong>Billing Address2 :</strong></td>
		<td><input type="text" name="c_billing_address2" value="<?=$c_res['c_billing_address2'];?>" id="c_billing_address2"/></td>
	</tr>
	<tr>
		<td><strong>City :</strong></td>
		<td><input type="text" name="c_billing_city" value="<?=$c_res['c_billing_city'];?>" id="c_billing_city"/></td>
	</tr>
	<tr>
		<td><strong>State :</strong></td>
		<td><input type="text" name="c_billing_state" value="<?=$c_res['c_billing_state'];?>" id="c_billing_state"/></td>
	</tr>
	<tr>
		<td><strong>Zip Code :</strong></td>
		<td><input type="text" name="c_billing_zipcode" value="<?=$c_res['c_billing_zipcode'];?>" id="c_billing_zipcode"/></td>
	</tr>
	<tr>
		<td><strong>Country :</strong></td>
		<td><input type="text" name="c_billing_country" value="<?=$c_res['c_billing_country'];?>" id="c_billing_country"/></td>
	</tr>
	<tr>
		<td><strong>Phone Number :</strong></td>
		<td><input type="text" name="c_phone_number" class="number" value="<?=$c_res['c_phone_number'];?>" id="c_phone_number"/></td>
	</tr>
	<tr>
		<td><strong>Extension :</strong></td>
		<td><input type="text" name="c_phone_extension" class="number" value="<?=$c_res['c_phone_extension'];?>" id="c_phone_extension"/></td>
	</tr>
	<tr>
		<td><strong>Fax Number :</strong></td>
		<td><input type="text" name="c_fax_number" class="number" value="<?=$c_res['c_fax_number'];?>" id="c_fax_number"/></td>
	</tr>
	<tr>
		<td>&nbsp;<input type="hidden" value="company_info" name="cmpy_info" /></td>
		<td>
			<input type="submit" value="submit" name="submit" class="ecsubmit"/>
			<input type="button" value="Cancel" name="cancel" onclick="location.href='index.php?page=company-information'"/>
		</td>
	</tr>
	<?}else if($user_id == 1){?>
		<tr>
		<td><strong>Billing Address1 :</strong></td>
		<td><span style="color:#0762A3"><?=$c_res['c_billing_address1'];?></span></td>
	</tr>
	<tr>
		<td><strong>Billing Address2 :</strong></td>
		<td><span style="color:#0762A3"><?=$c_res['c_billing_address2'];?></span></td>
	</tr>
	<tr>
		<td><strong>City :</strong></td>
		<td><span style="color:#0762A3"><?=$c_res['c_billing_city'];?></span></td>
	</tr>
	<tr>
		<td><strong>State :</strong></td>
		<td><span style="color:#0762A3"><?=$c_res['c_billing_state'];?></span></td>
	</tr>
	<tr>
		<td><strong>Zip Code :</strong></td>
		<td><span style="color:#0762A3"><?=$c_res['c_billing_zipcode'];?></span></td>
	</tr>
	<tr>
		<td><strong>Country :</strong></td>
		<td><span style="color:#0762A3"><?=$c_res['c_billing_country'];?></span></td>
	</tr>
	<tr>
		<td><strong>Phone Number :</strong></td>
		<td><span style="color:#0762A3"><?=$c_res['c_phone_number'];?></span></td>
	</tr>
	<tr>
		<td><strong>Extension :</strong></td>
		<td><span style="color:#0762A3"><?=$c_res['c_phone_extension'];?></span></td>
	</tr>
	<tr>
		<td><strong>Fax Number :</strong></td>
		<td><span style="color:#0762A3"><?=$c_res['c_fax_number'];?></span></td>
	</tr>
	<?}?>
	
	<input type="hidden" name="chidden" value="<?=$c_res['c_id']?>" id="cid"/>
</table>
</form>
</fieldset>